import os

from setuptools import Extension
from setuptools import setup
from setuptools.command.build_py import build_py
from Cython.Build import cythonize


class CustomBuildCommand(build_py):
    def run(self):
        super().run()
        build_lib_dir = self.build_lib
        for root, _, files in os.walk(build_lib_dir):
            for file in files:
                if file.endswith(".py"):
                    os.remove(os.path.join(root, file))


setup(
    ext_modules=cythonize(
        Extension("*", ["src/{{cookiecutter.project_slug}}/**/*.py"]),
        build_dir="build"
    ),
    cmdclass={
        "build_py": CustomBuildCommand,
    },
)
